package servlets;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;

public class OtherServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        System.out.println("******************************************");



        String name = req.getParameter("name");
        System.out.println("name = "+name);
        String age = req.getParameter("age");
        System.out.println("age = "+age);



        //从请求中获取指定名称的域属性
        String name1 = (String) req.getAttribute("name");

        String address = (String) req.getAttribute("address");

        System.out.println("name1 = "+name1);
        System.out.println("address = "+address);


        //获取请求中的所有域属性名称
        Enumeration<String> names = req.getAttributeNames();
        while (names.hasMoreElements()) {
            String s = names.nextElement();
            System.out.println(s + "============" + req.getAttribute(s));
        }

        System.out.println("============================================");


        //获取请求的URL
        StringBuffer requestURL = req.getRequestURL();
        System.out.println("requestURL = "+requestURL);

        //获取请求的URI，URI去掉请求协议及主机后的剩余部分

        String requestURI = req.getRequestURI();
        System.out.println("requestURI = "+requestURI);


        //获取当前WEb应用的根路径
        String contextPath = req.getContextPath();
        System.out.println("contextPath = "+contextPath);

        //获取客户端IP
        String remoteAddr = req.getRemoteAddr();
        System.out.println("remoteAddr = " + remoteAddr);


        String servletPath = req.getServletPath();
        System.out.println("servletPath = "+servletPath);


        String pathInfo = req.getPathInfo();
        System.out.println("pathInfo = "+pathInfo);


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        doGet(req,resp);
    }
}
